package com.znsd.zl.app.wechat.config;

import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * <p>
 *      微信支付配置类
 * </p>
 *
 * @ClassName MyWxPayConfig
 * @Description TODO
 * @Author jaypdd
 * @Date 2020/8/27 20:37
 * @Version v1.0
 */
@Configuration
@Slf4j
@Data
@Accessors(chain = true)
public class WeChatPayConfig {

	/**
	 * 本机ip地址
	 */
	public static final String LOCAL_IP;

	static {
		InetAddress localHost = null;
		try {
			localHost = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			e.printStackTrace();
			log.info("本机ip初始化失败 ip：{}，{}，", WeChatPayConfig.LOCAL_IP, e.getMessage(), e);
		}finally {
			LOCAL_IP = null == localHost ? "127.0.0.1" : localHost.toString().split("/")[1];;
		}
	}

	@Resource
	private ApplicationContext ac;

	/**
	 * 小程序 appId
	 */
	@Value("${wechat.appid}")
	private String appId;

	/**
	 * 小程序 appSecret
	 */
	@Value("${wechat.secret}")
	private String secret;

	/**
	 * 商户id
	 */
	@Value("${wechat.mch-id}")
	private String mchId;

	/**
	 * 商户api密钥
	 */
	@Value("${wechat.mch-key}")
	private String mchKey;

	/**
	 * 商户证书
	 */
	@Value("${wechat.mch-cert}")
	private String mchCert;

	/**
	 * 支付回调地址
	 */
	@Value("${wechat.notify-url}")
	private String notifyUrl;

	/**
	 * 微信统一下单地址
	 */
	@Value("${wechat.pay-url}")
	private String payUrl;

	/**
	 * 支付类型
	 */
	@Value("${wechat.trade_type}")
	private String tradeType;

}
